<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <DelayriskOptModal @register="registerDelayriskOptModal" @success="handleSuccess"></DelayriskOptModal>
  </div>
</template>
<script lang="ts" setup name="delayrisk">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/Table';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { columns, searchFormSchema } from './data/data';
import { Api } from './data/api';
import { useModal } from '@apps/antd-admin/src/components/modal';
import DelayriskOptModal from './components/DelayriskOptModal.vue';

const [registerDelayriskOptModal, { openModal: openDelayriskOptModal }] = useModal();
const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'delayrisk-template',
  tableProps: {
    //表格标题
    title: '延误险信息',
    //主键字段
    rowKey: 'delayriskId',
    //列表接口
    listUrl: Api.page,
    //删除接口
    delUrl: Api.remove,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 100,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  },
});

const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '预约处理',
      onClick: handleOpt.bind(null, record),
      auth: 'ACTION_delayriskCheck',
    },
  ];
}

function handleOpt(record) {
  openDelayriskOptModal(true, {
    record,
    isUpdate: false,
  });
}
</script>
